package com.csdj.music.controller;

import com.csdj.music.utils.FastDFSClient;
import com.csdj.music.vo.RespBean;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

/**
 * @ClassName: FileUploadController
 * @Author: ZouLi
 * @Description: 文件上传控制器
 * @Date: 2023/3/21 13:57
 **/
@RestController
@Api(tags = "文件上传控制器")
public class FileUploadController {

    /**
     * @Description: 文件上传测试
     * @Param [file]
     * @Return com.csdj.music.vo.RespBean
     * @Throws
     **/
    @PostMapping("/upload")
    @ApiOperation(value = "文件上传测试")
    @ApiImplicitParams({@ApiImplicitParam(name = "file", value = "文件", dataType = "MultipartFile")})
    public RespBean upload(MultipartFile file){
        String[] res = FastDFSClient.uploadFile(file);
        String url = "";
        try {
            url = FastDFSClient.getFilePath() + res[0] +"/"+res[1];
        } catch (Exception e) {
            e.printStackTrace();
        }
        return RespBean.success("上传成功！", url);
    }
}
